package com.wqr.controller;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import com.wqr.pojo.Delicious;
import com.wqr.pojo.Discuss;
import com.wqr.pojo.User;
import com.wqr.service.DeliciousService;
import com.wqr.service.DiscussService;
import com.wqr.service.UserService;

@Controller
public class ShowController {
	@Autowired
    public DeliciousService deliciousService;
	@Autowired
    public UserService userService;
	@Autowired
    public DiscussService discussService;
	
	@RequestMapping("/showDeliciousPractice")
	public String showDeliciousPractice(@RequestParam("deliciousId") Integer deliciousId,Model model,
			Delicious delicious,Discuss discuss) throws Exception {
		delicious.setDeliciousId(deliciousId);
		List<Delicious> itemList = deliciousService.list(delicious);
		model.addAttribute("itemList", itemList);
		
		discuss.setDeliciousId(deliciousId);
		List<Discuss> itemList2 = discussService.selectDiscuss(discuss);
		model.addAttribute("itemList2", itemList2);
	    return "showMessage"; 
	}
	@RequestMapping("/showUserDeliciousPractice")
	public String showUserDeliciousPractice(@RequestParam("deliciousId") Integer deliciousId,Model model,
			Delicious delicious,Discuss discuss) throws Exception {
		delicious.setDeliciousId(deliciousId);
		List<Delicious> itemList = deliciousService.list(delicious);
		model.addAttribute("itemList", itemList);
		discuss.setDeliciousId(deliciousId);
		List<Discuss> itemList2 = discussService.selectDiscuss(discuss);
		model.addAttribute("itemList2", itemList2);
	    return "showUserDeliciousPractice"; 
	}

	@RequestMapping("/userMyDelicious")
	public String userMyDelicious(@RequestParam("loginId") Integer loginId,Model model,Delicious delicious) throws Exception {
		delicious.setLoginId(loginId);
		List<Delicious> itemList = deliciousService.selectByUser(delicious);
		model.addAttribute("itemList", itemList);
	    return "userMyDelicious"; 
	}
	
	@RequestMapping("/userUser")
	public String userUser(@RequestParam("loginId") Integer loginId,Model model,User user) throws Exception {
		user.setLoginId(loginId);
		List<User> itemList = userService.list(user);
		model.addAttribute("itemList", itemList);
	    return "showUserDeliciousPractice"; 
	}
	@RequestMapping("/userIndex")
    public String userIndex(){
        return "userIndex";
    }
	@RequestMapping("/Index")
    public String Index(){
        return "index";
    }
	@RequestMapping("/register")
    public String register(){
        return "register";
    }
	@RequestMapping("/adminMain")
    public String admin_login(){
        return "adminMain";
    }
 	@RequestMapping("/login")
    public String login() {
        return "login";
    }
 	@RequestMapping("/userModifyPassword")
    public String userModifyPassword() {
        return "userModifyPassword";
    }
 	
 	@RequestMapping("/userAdddDelicious")
    public String userAdddDelicious() {
        return "userAddDelicious";
    }
}
